<template>
  <div class="level">
    <h1>医院</h1>
    <div class="content">
      <div class="left">等级:</div>
      <ul class="hospital">
        <li :class="{ active: activeFlag == '' }" @click="changeLevel('')">全部</li>
        <li v-for=" item in levelArr" :class="{ active: activeFlag == item.value }" @click=" changeLevel(item.value)">{{
          item.name }}</li>
      </ul>
    </div>
  </div>
</template>

<script setup lang="ts">
import { reqhospitalLevelRegion } from '@/api/home';
import { onMounted, ref } from 'vue';
import type { HOSPITALLEVELANDREGIONResponse, HOSPITALLEVELANDREGIONArr } from '@/api/home/type';
//存放等级数据
let levelArr = ref<HOSPITALLEVELANDREGIONArr>([])
//控制等级高亮数组
let activeFlag = ref<string>('')
onMounted(
  () => {
    GetLevel()
  })

let GetLevel = async () => {
  let result: HOSPITALLEVELANDREGIONResponse = await reqhospitalLevelRegion('HosType');
  //存取医院等级数据
  levelArr.value = result.data
  // console.log('我是等级数据', levelArr);
}

//改变医院等级数据
let changeLevel = (level: string) => {
  // console.log(level);
  activeFlag.value = level
  console.log('触发事件');

  //触发自定义事件
  $emit('getLevel', level)
}


let $emit = defineEmits(['getLevel'])
</script>

<script lang="ts">
export default {
  name: 'Level'
}</script>

<style scoped lang="scss">
.level {
  h1 {
    color: #7f7f7f;
    font-weight: 20px;
    margin: 10px 0px;
    cursor: default;
  }

  .content {
    display: flex;
    color: #7f7f7f;
    cursor: default;

    .left {}

    .hospital {
      margin-left: 10px;
      display: flex;

      li {
        margin-right: 10px;

        &.active {
          color: #55a6fe;
        }
      }

      li:hover {
        color: #55a6fe;
        cursor: pointer;
      }
    }
  }
}
</style>